package com.gdk.ksoft.assembly.utils;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;

/**
 * Created by Mrper on 2014/11/25.
 * 图片辅助类
 */
public class BitmapUtils {

    /**
     * 获取绘制的图片数据
     * @param width
     * @param height
     * @param config
     * @return
     */
     public static Bitmap getTextBitmap(String text,int width,int height,Bitmap.Config config){
         Paint paint = new Paint();
         paint.setAntiAlias(true);
         Bitmap bmp = Bitmap.createBitmap(width,height,config);
         Canvas canvas = new Canvas(bmp);
         canvas.drawColor(Color.TRANSPARENT);
         float textWidth = paint.measureText(text);
         Paint.FontMetrics fm = paint.getFontMetrics();
         paint.setColor(Color.WHITE);
         paint.setTextSize(16f);
         paint.setLinearText(true);
         canvas.drawText(text,(width-textWidth)/2,(height-(fm.ascent+fm.leading+fm.descent))/2,paint);
         return bmp;
     }

}
